//
//  BTCourseDetailHeader.m
//  BaxTer
//
//  Created by wsj2015 on 16/9/2.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "BTCourseDetailHeader.h"
#import "UIImageView+BTimageView.h"
#import "HELPDFfileCacheTool.h"
#import "BTMarchs.h"
@implementation BTCourseDetailHeader



- (void)awakeFromNib{
  
    
//    isExpend = NO;
//    self.expendBtn.transform = CGAffineTransformRotate( self.expendBtn.transform, M_PI/2);
//    self.iconView.image = [UIImage imageNamed:@"1.jpg"];
   
    CGFloat f = kScreenFactor;
    self.iconViewWidth.constant = f * 136;
    self.bgHegithC.constant = f * 220;
    [super awakeFromNib];
    
    self.testBtn.backgroundColor =[UIColor whiteColor];
    self.testBtn.layer.borderWidth = 1;
    self.testBtn.layer.borderColor = kMainColor.CGColor;
   
    
}




//- (IBAction)action:(id)sender {
//    
//    isExpend = !isExpend;
//    
//
//    [UIView animateWithDuration:.35 animations:^{
//         self.expendBtn.transform =CGAffineTransformRotate( self.expendBtn.transform, M_PI);
//    }];
//    if (self.clickBlock) {
//        self.clickBlock(isExpend,self.contentLabel);
//    }
//    
//    
//   
//}
- (IBAction)backAction:(id)sender {
    if (self.pageBack) {
        self.pageBack();
    }
}

- (IBAction)learnAction:(id)sender {
    
    if (self.beginLearn) {
        self.beginLearn();
    }
    
    
}
- (IBAction)testAction:(id)sender {
    
    if (self.testBlock) {
        self.testBlock();
    }
}

+ (instancetype)deatilHeader{
  
    return  [[NSBundle mainBundle] loadNibNamed:@"BTCourseDetailHeader" owner:nil options:0].lastObject;

}

- (IBAction)collectAction:(UIButton *)sender {
    
    if (self.collectBlock) {
        self.collectBlock(sender);
    }
    
}
- (IBAction)priseAction:(UIButton *)sender {
    if (self.priseBlock) {
        self.priseBlock( sender);
    }
    
}
- (IBAction)downLoadAction:(UIButton *)sender {
    
    if ( sender.selected == YES) {
        return;
    }
    if (self.dowloadBlock) {
        self.dowloadBlock();
    }
    
}
- (IBAction)ratingAction:(id)sender {
    if (self.ratingBlock) {
        self.ratingBlock();
    }
    
}
- (void)setModel:(BTCourseModel *)model{
    _model = model;
   
/*
    "courseImage": "http://media.hulijia360.com/media/upload/image/baxter/2016-10-21/df24fa01-6f14-43bd-a0f6-fb190d5d97a8.jpg",
    "courseAbstract": "1",
    "courseUrl": "upload\\2016\\2016-10-21\\36725948-f76a-4ce5-b489-b1de255c13ea.pdf",
    "thumbUrl": "http://media.hulijia360.com/media/upload/thumb/baxter/2016-10-21/df24fa01-6f14-43bd-a0f6-fb190d5d97a8.jpg",
    "coursePage": 1,
    "needSecond": null,
    "expireDays": 1,
    "status": 1,
    "auditState": 1,

    "courseScore": 1,
    "viewNum": 17,
    "courseStatus": 0,
    "islike": 0,
    "iscollect": 0,
    "userCourseScore": null,
    "lastReadTime": null,
    "id": 69
*/
    [self.iconView bt_setImageWithUrl:model.courseImage];
    
    self.scanNumber.wsj_text = [NSString stringWithFormat:@"%@人查看",model.viewNum];
    //"islike": null,
    //"iscollect": null,
     self.collectionBtn.selected = [model.iscollect integerValue]?YES:NO;
    
     self.priseBtn.selected = [model.islike integerValue]?YES:NO;
    
    if ([model.courseType integerValue] == 2) {
        //微课课程是不支持下载的
        self.downloadBtn.enabled  =NO;
        self.downloadBtn.selected = NO;
    }else{
        
        BOOL isMP4 = NO;
        if ([model.courseType integerValue] == 1) {
            isMP4 = YES;
        }
        //有没有下载
        self.downloadBtn.selected = NO;
        NSString *path = [HELPDFfileCacheTool isChchedWithPdfFilename:model.courseName isMP4:isMP4];
        if (path) {
            self.downloadBtn.selected = YES;
        }else{
            self.downloadBtn.selected = NO;
        }

    }
    
    self.ratingView.value = [model.courseScore floatValue] /2;
  
    self.scoreL.text = [NSString stringWithFormat:@"%.f分",[model.courseScore floatValue] ];
    self.coureseName.text = model.courseName;
    
    self.contentLabel.text = model.courseAbstract;
    
  
    
    
    NSString *stateStr;
    switch ([model.courseStatus integerValue]) {
//            0：表示未开始
//            1：表示未学完，主要针对图文和视频。微课和长图可以略过这个状态。
//            2：表示待评分。
//            3：表示待测试，评分完未测试的课程。仅针对有测试的课程，
//            4：表示已完成。
        case 0:
            stateStr = @"未开始";
             self.ableTotest = NO;
            break;
        case 1:
            stateStr = @"未学完";
             self.ableTotest = NO;
            break;
        case 2:
            stateStr = @"待评分";
             self.ableTotest = NO;
            break;
        case 3:
            stateStr = @"待测试";
            self.ableTotest = YES;
            break;
        case 4:
            stateStr = @"已完成";
            self.ableTotest = NO;
            break;
            
        default:
            break;
    }
    self.scoreStatueL.text = stateStr;
    
}
- (void)setAbleTotest:(BOOL)ableTotest{
    CGFloat f = kScreenFactor ;
    if (ableTotest) {
        
        self.testBtnWidth.constant =(f * 136 -8)/2 ;
        self.learnBtnWidth.constant = (f * 136 -8)/2;
        self.testBtn.hidden = NO;
    }else{
       self.testBtnWidth.constant = (f * 136 -8)/4;
        self.learnBtnWidth.constant = (f * 136 -8)/4 + 20 * f;
       self.testBtn.hidden = YES;
 
     
    }
    
   
   
   

}


@end
